package org.raj.package2;

import java.util.Date;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.raj.package1.Account1;

public class HibernateTester {
	
	public static void main(String [] args){
		Account1 account1 =new Account1();
	account1.setUserId(1);
		account1.setPassword("password1");
		account1.setJoinedDate(new Date());
		account1.setEmail("rajdaha1@gmail.com");
		account1.setDescription("He is hard working1");
		
		Account1 account2 =new Account1();
		account2.setUserId(2);
			account2.setPassword("password2");
			account2.setJoinedDate(new Date());
			account2.setEmail("rajdahal2@gmail.com");
			account2.setDescription("He is hard working2");
		
		
		try {
			SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
			Session session=sessionFactory.openSession();
			session.beginTransaction();
			
			session.save(account1);
			session.save(account2);
			session.getTransaction().commit();
			session.close();
			
			Account1 account = null;
			session=sessionFactory.openSession();
			session.beginTransaction();
	//		 account1 = null;
			for (int i = 1; i < 3; i++) {
				account = (Account1)session.get(Account1.class, i);
				System.out.println(account.getUserId());
		//		session.close();
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			System.out.println("something is going wrong");
			e.printStackTrace();
		}
	}// main method closer

}// class closer
